ostree export: Add --subpath support
authorAlexander Larsson <alexl@redhat.com>
Mon, 18 Apr 2016 12:17:08 +0000 (14:17 +0200)
committerColin Walters (automation) <walters+githubbot@verbum.org>
Tue, 19 Apr 2016 12:28:06 +0000 (12:28 +0000)
This lets you export a subset of a commit.

Closes: #265
Approved by: cgwalters

src/libostree/ostree-repo-libarchive.c
src/ostree/ot-builtin-export.c
tests/test-export.sh

index 7a30192c78e62da0333401f5031dbdf47155f650..6e6e9806cc0dc76c52c0afa241d6dba5f8d77fd8 100644 (file)
@@ -480,7 +480,7 @@ file_to_archive_entry_common (GFile         *root,
   g_autoptr(GVariant) xattrs = NULL;
   time_t ts = (time_t) opts->timestamp_secs;
 
-  if (pathstr && !pathstr[0])
+  if (pathstr == NULL || !pathstr[0])
     {
       g_free (pathstr);
       pathstr = g_strdup (".");
index cccb50e727dd80ef58bf32fa846e0f6b6b463df4..9a7842abb6c8049ed3cec3210162f6edda48e4e3 100644 (file)
 #endif
 
 static char *opt_output_path;
+static char *opt_subpath;
 static gboolean opt_no_xattrs;
 
 static GOptionEntry options[] = {
   { "no-xattrs", 0, 0, G_OPTION_ARG_NONE, &opt_no_xattrs, "Skip output of extended attributes", NULL },
+  { "subpath", 0, 0, G_OPTION_ARG_STRING, &opt_subpath, "Checkout sub-directory PATH", "PATH" },
   { "output", 'o', 0, G_OPTION_ARG_STRING, &opt_output_path, "Output to PATH ", "PATH" },
   { NULL }
 };
@@ -60,6 +62,7 @@ ostree_builtin_export (int argc, char **argv, GCancellable *cancellable, GError
   gboolean ret = FALSE;
   const char *rev;
   g_autoptr(GFile) root = NULL;
+  g_autoptr(GFile) subtree = NULL;
   g_autofree char *commit = NULL;
   g_autoptr(GVariant) commit_data = NULL;
   struct archive *a;
@@ -124,7 +127,12 @@ ostree_builtin_export (int argc, char **argv, GCancellable *cancellable, GError
 
   opts.timestamp_secs = ostree_commit_get_timestamp (commit_data);
 
-  if (!ostree_repo_export_tree_to_archive (repo, &opts, (OstreeRepoFile*)root, a,
+  if (opt_subpath)
+    subtree = g_file_resolve_relative_path (root, opt_subpath);
+  else
+    subtree = g_object_ref (root);
+
+  if (!ostree_repo_export_tree_to_archive (repo, &opts, (OstreeRepoFile*)subtree, a,
                                            cancellable, error))
     goto out;
 
index 1e81a2e97f4dfaf77e4ccbd3a889bbf5d722ce08..8666e1772cd6ed64220c9749b42d5083562330f6 100755 (executable)
@@ -23,7 +23,7 @@ set -euo pipefail
 
 setup_test_repository "archive-z2"
 
-echo '1..2'
+echo '1..3'
 
 $OSTREE checkout test2 test2-co
 $OSTREE commit --no-xattrs -b test2-noxattrs -s "test2 without xattrs" --tree=dir=test2-co
@@ -35,10 +35,20 @@ mkdir t
 (cd t && tar xf ../test2.tar)
 ${CMD_PREFIX} ostree --repo=repo diff --no-xattrs test2-noxattrs ./t > diff.txt
 assert_file_empty diff.txt
-rm test2.tar diff.txt t -rf
 
 echo 'ok export gnutar diff (no xattrs)'
 
+cd ${test_tmpdir}
+${OSTREE} 'export' test2-noxattrs --subpath=baz -o test2-subpath.tar
+mkdir t2
+(cd t2 && tar xf ../test2-subpath.tar)
+${CMD_PREFIX} ostree --repo=repo diff --no-xattrs ./t2 ./t/baz > diff.txt
+assert_file_empty diff.txt
+
+echo 'ok export --subpath gnutar diff (no xattrs)'
+
+rm test2.tar test2-subpath.tar diff.txt t t2 -rf
+
 cd ${test_tmpdir}
 ${OSTREE} 'export' test2 -o test2.tar
 ${OSTREE} commit -b test2-from-tar -s 'Import from tar' --tree=tar=test2.tar